From 186b17976c76e2f18b2a91148baf964d18014774 Mon Sep 17 00:00:00 2001 From: "emellor@ewan" Date: Tue, 4 Oct 2005 18:23:58 +0100 Subject: [PATCH] Clean up domains if creation/restoration fails. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/XendDomainInfo.py | 34 +++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 994cd4e130..782a1b7d68 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -129,9 +129,13 @@ def create(config): log.debug("XendDomainInfo.create(%s)", config) vm = XendDomainInfo(getUuid(), parseConfig(config)) - vm.construct() - vm.refreshShutdown() - return vm + try: + vm.construct() + vm.refreshShutdown() + return vm + except: + vm.destroy() + raise def recreate(xeninfo): @@ -195,13 +199,23 @@ def restore(config): except TypeError, exn: raise VmError('Invalid ssidref in config: %s' % exn) - vm = XendDomainInfo(uuid, parseConfig(config), - xc.domain_create(ssidref = ssidref)) - vm.storeVmDetails() - vm.configure() - vm.create_channel() - vm.storeDomDetails() - return vm + domid = xc.domain_create(ssidref = ssidref) + if domid <= 0: + raise VmError('Creating domain failed for restore') + try: + vm = XendDomainInfo(uuid, parseConfig(config), domid) + except: + xc.domain_destroy(domid) + raise + try: + vm.storeVmDetails() + vm.configure() + vm.create_channel() + vm.storeDomDetails() + return vm + except: + vm.destroy() + raise def parseConfig(config): -- 2.30.2